package com.christianposta.learnddd.domain.model.cargo;

import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.christianposta.learnddd.domain.model.handling.HandlingType;
import com.christianposta.learnddd.domain.model.location.Location;
import com.christianposta.learnddd.domain.model.voyage.Voyage;
import com.christianposta.learnddd.domain.shared.ValueObject;

public class HandlingActivity implements ValueObject<HandlingActivity> {
	
	private HandlingType type;
	private Location location;
	private Voyage voyage;
	
	public HandlingActivity(final HandlingType type, final Location location){
		Validate.notNull(type, "HandlingType is required.");
		Validate.notNull(location, "A location is required.");
		
		this.type = type;
		this.location = location;
	}
	
	public HandlingActivity(final HandlingType type, final Location location, final Voyage voyage){
		Validate.notNull(type, "HandlingType is required.");
		Validate.notNull(location, "A location is required.");
		Validate.notNull(voyage, "A voyage is required.");
		
		this.type = type;
		this.location = location;
		this.voyage = voyage;
	}
	
	public HandlingType type(){
		return this.type;
	}
	
	public Location location(){
		return this.location;
	}
	
	public Voyage voyage(){
		return this.voyage;
	}

	public boolean sameValueAs(HandlingActivity other) {
		return new EqualsBuilder().append(this.type, other.type)
			.append(this.location, other.location)
			.append(this.voyage, other.voyage)
			.isEquals();
	}
	
	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(this.type)
			.append(this.location)
			.append(this.voyage)
			.toHashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == this) return true;
		if(obj == null || getClass() != obj.getClass()) return false;
		
		HandlingActivity other = (HandlingActivity)obj;
		return sameValueAs(other);
	}

}
